package com.hcg.distributedtx.service.cm.impl;

//import com.hcg.distributedtx.cm.mapper.CmUserMapper;
//import com.hcg.distributedtx.cm.service.CmUService;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hcg.distributedtx.domain.User;
import com.hcg.distributedtx.mapper.cm.CmUserMapper;
import com.hcg.distributedtx.service.cm.CmUService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("cmUserService")
public class CmUserServiceImpl implements CmUService {


    @Autowired
    private CmUserMapper cmUserMapper;

    @Override
    @Transactional
    public void saveUser(User user) {
        cmUserMapper.insert(user);
//        int i  = 1/0;
//        cmUserMapper.addUser(user.getUid(),user.getNickname(),user.getName(),user.getPassword(),user.getSalt(), user.getMobile());
    }

    @Override
    public PageInfo<User> listUser(Integer pageNum, Integer pageSize) {
        if(pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 5;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = cmUserMapper.selectAll();
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return pageInfo;
    }

    @Override
    public List<User> listUsers(Integer pageNum, Integer pageSize) {
        if(pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 5;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<User> users = cmUserMapper.selectAll();
        return users;
    }


}
